package cn.edu.tsinghua.training.cms.demo.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.tsinghua.training.cms.demo.entity.Log;
import cn.edu.tsinghua.training.cms.demo.service.LogService;

@SuppressWarnings("serial")
@Results({
	@Result(name="list", location="log_list", type="redirectAction"),
	@Result(name="log_list", location="/log/log_list.jsp", type="redirect"),
	@Result(name="log_search", location="/log/log_edit.jsp", type="redirect")
})
public class LogAction extends BaseAction {

	private Log log;
	@Autowired
	private LogService logService;
	
	@Action("log_add")
	public String add() throws Exception {
		logService.add(log);
		return "list";
	}
	
	@Action("log_list")
	public String list() throws Exception {
		getSession().put("list", logService.queryAll());
		return "log_list";
	}
	
	@Action("log_search")
	public String search() throws Exception {
		getSession().put("log", logService.queryById(log.getId()));
		return "log_search";
	}
	
	@Action("log_update")
	public String update() throws Exception {
		logService.update(log);
		return "list";
	}
	
	@Action("log_remove")
	public String remove() throws Exception {
		logService.delete(log);
		return "list";
	}
	
//	setters and getters

	public void setLog(Log log) {
		this.log = log;
	}
	
	public Log getLog() {
		return log;
	}

}